package com.lemon.common.config;

import lombok.Data;
import org.apache.commons.lang3.time.FastDateFormat;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 文件上传配置
 *
 * @author ymh
 * @date 2019-04-06 13:35
 */
@Data
@Component
@ConfigurationProperties(prefix = "file.upload")
public class UploadConfig {

    // 上传文件保存目录
    String path = "C:/tmp";

    /**
     * 拼接上传文件的相对路径
     *
     * @param fileName
     * @return
     */
    public String getRelaPath(String fileName) {
        String date = FastDateFormat.getInstance("yyyy/MM/dd").format(new Date());
        String relaPath = new StringBuilder("/upload/")
                .append(date)
                .append("/")
                .append(fileName)
                .toString();
        return relaPath;
    }
}


